In [1]:
import pandas as pd
import py2neo
graph = py2neo.Graph(password="password")
In [2]:
query = """
MATCH
(t:Type)-[:BELONGS_TO]->(s:Subdomain),
(t)-[:HAS_CHANGE]->(ch:Change),
(t)-[:HAS_MEASURE]->(co:Coverage),
(t)-[:DECLARES]->(m:Method)
OPTIONAL MATCH
(t)-[:HAS_BUG]->(b:BugInstance)
RETURN
s.name as ASubdomain,
COUNT(DISTINCT t) as Types,
COUNT(DISTINCT ch) as Changes,
AVG(co.ratio) as Coverage,
COUNT(DISTINCT b) as Bugs,
SUM(DISTINCT m.lastLineNumber) as Lines
ORDER BY Coverage ASC, Bugs DESC
"""
In [3]:
result = pd.DataFrame(graph.data(query))
result
Out[3]:
In [4]:
plot_data = result.copy()
plot_data = plot_data.rename(
columns= {
"Changes" : "Investment",
"Coverage" : "Utilization",
"Lines" : "Size"})
plot_data
Out[4]:
In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
def plot_portfolio_diagramm(plot_data, name):
x = "Investment"
y = "Utilization"
ax = plot_data.plot.scatter(
x,
y,
s=plot_data.Size,
alpha=0.7,
title="Return on Investment ({})".format(name),
figsize=[10,7],
fontsize=14
)
ax.title.set_size(24)
ax.title
plt.xlabel(x, fontsize=18)
plt.ylabel(y, fontsize=18)
ax.plot(
[plot_data[x].max()/2, plot_data[x].max()/2],
[0, plot_data[y].max()], color='k', linestyle='--', linewidth=0.6)
ax.plot(
[0, plot_data[x].max()],
[plot_data[y].max()/2,plot_data[y].max()/2], color='k', linestyle='--', linewidth=0.6)
ax.text(plot_data[x].max()*1/4, plot_data[y].max()*3/4, "Success", ha="center", fontsize=24)
ax.text(plot_data[x].max()*3/4, plot_data[y].max()*3/4, "Beware", ha="center", fontsize=24)
ax.text(plot_data[x].max()*1/4, plot_data[y].max()*1/4, "Watch", ha="center", fontsize=24)
ax.text(plot_data[x].max()*3/4, plot_data[y].max()*1/4, "Failure", ha="center", fontsize=24)
In [6]:
plot_portfolio_diagramm(plot_data, "Subdomains")
In [7]:
query = """
MATCH
(t:Type)-[:IS_A]->(ta:TechnicalAspect),
(t)-[:HAS_CHANGE]->(ch:Change),
(t)-[:HAS_MEASURE]->(co:Coverage),
(t)-[:DECLARES]->(m:Method)
OPTIONAL MATCH
(t)-[:HAS_BUG]->(b:BugInstance)
RETURN
ta.name as ATechnicalAspect,
COUNT(DISTINCT t) as Types,
COUNT(DISTINCT ch) as Investment,
AVG(co.ratio) as Utilization,
COUNT(DISTINCT b) as Bugs,
SUM(DISTINCT m.lastLineNumber) as Size
ORDER BY Utilization ASC, Bugs DESC
"""
In [8]:
result = pd.DataFrame(graph.data(query))
result
Out[8]:
In [9]:
plot_portfolio_diagramm(result, "Technical Aspects")